//全选或全不选
function checkAll(field) {
	var selectFlags = document.getElementsByName("selectFlag");
	for (var i=0; i<selectFlags.length; i++) {
		selectFlags[i].checked = field.checked;
	}
}
//点击更新
function clickOpen(bida,bidb){
	//把显示的值
	if(bida != "" && bidb != ""){
		document.getElementById(bida).style.display = "none";
		document.getElementById(bidb).style.display = "block";
	}
}

function clickExist(bida,bidb){
	//把显示的值
	if(bida != "" && bidb != ""){
		document.getElementById(bida).style.display = "block";
		document.getElementById(bidb).style.display = "none";
	}
}

function addvoterUI(){
	window.location.href="/webvote/vote.do?action=addvoterUI";
}

//表单提交校验
function checkfile(){
  var file=document.getElementById('myfile').value;
 // window.alert(file);
  if(file==''){
  	Ext.MessageBox.alert('系统提示',"请选择上传头像！");
  }
  else{
    document.fileForm.submit();
  }
}

function addVoter(){
  Ext.MessageBox.confirm('系统提示','添加评选人信息？',verifyadd);
}
function verifyadd(btn){
 if(btn == 'yes'){
  var viname=document.getElementById('viname').value;
  var visex=document.getElementById('visex').options[document.getElementById('visex').selectedIndex].value;
  var viage=document.getElementById('viage').value;
  var viintro=document.getElementById('viintro').value;
  var oEditor = FCKeditorAPI.GetInstance('vicontent');
	editorValue = oEditor.GetHTML()
  var vicontent=editorValue;
  var vitype=document.getElementById('vitype').options[document.getElementById('vitype').selectedIndex].value;
  var file=document.getElementById('myfile').value;
  var viimg=document.getElementById('viimg').value;
  var token=document.getElementById('org.apache.struts.taglib.html.TOKEN').value;//用于传令牌值
  //window.alert(viimg);
  var reg=/^\d{1,3}$/;
  if(viname==''){
  	Ext.MessageBox.alert('系统提示',"评选人姓名不能为空！");
  }
  else if(viname.length>20){
    Ext.MessageBox.alert('系统提示',"评选人姓名超出20字！");
  }
  else if(!reg.exec(viage)){
    Ext.MessageBox.alert('系统提示',"年龄格式不对，请输入1-100之间的数字！");
  }
   else if(viintro==''){
    Ext.MessageBox.alert('系统提示',"信息简介不能为空！");
  }
  else if(vicontent==''){
    Ext.MessageBox.alert('系统提示',"事迹内容不能为空！");
  }
  else if(vitype=='select'){
    Ext.MessageBox.alert('系统提示',"请选择评选类型！");
  }
  else if(file==''){
  	Ext.MessageBox.alert('系统提示',"请选择上传头像！");
  }
  else{
  $.post("/webvote/vote.do?action=addvoter",{"viname":viname,"visex":visex,"viage":viage,"viintro":viintro,"vicontent":vicontent,
  "vitype":vitype,"viimg":viimg,"org.apache.struts.taglib.html.TOKEN":token},function(text){
		if(text == "success"){
			Ext.MessageBox.alert('系统提示',"添加系统用户成功！");
		}
		else if(text == "error")
		{
			Ext.MessageBox.alert('系统提示',"添加系统用户失败！");
		}
		else if(text == "nopower")
		{
			Ext.MessageBox.alert('系统提示',"权限不足！");
		}
		else if(text == "repeat")
		{
			Ext.MessageBox.alert('系统提示',"请不要重复操作！");
		}
	});
	}
}else{
	Ext.MessageBox.alert('系统提示','您取消了本次任务！');
}
}

function updateVoter(){
  Ext.MessageBox.confirm('系统提示','修改评选人信息？',verifyupdate);
}
function verifyupdate(btn){
 if(btn == 'yes'){
  var viid=document.getElementById('viid').value;
  var viname=document.getElementById('viname').value;
  var visex=document.getElementById('visex').options[document.getElementById('visex').selectedIndex].value;
  var viage=document.getElementById('viage').value;
  var viintro=document.getElementById('viintro').value;
  var oEditor = FCKeditorAPI.GetInstance('vicontent');
	editorValue = oEditor.GetHTML()
  var vicontent=editorValue;
  var vitype=document.getElementById('vitype').options[document.getElementById('vitype').selectedIndex].value;
  var file=document.getElementById('myfile').value;
  var viimg=document.getElementById('viimg').value;
  var token=document.getElementById('org.apache.struts.taglib.html.TOKEN').value;//用于传令牌值
  //window.alert(viimg);
  var reg=/^\d{1,3}$/;
  if(viname==''){
  	Ext.MessageBox.alert('系统提示',"评选人姓名不能为空！");
  }
  else if(viname.length>20){
    Ext.MessageBox.alert('系统提示',"评选人姓名超出20字！");
  }
  else if(!reg.exec(viage)){
    Ext.MessageBox.alert('系统提示',"年龄格式不对，请输入1-100之间的数字！");
  }
   else if(viintro==''){
    Ext.MessageBox.alert('系统提示',"信息简介不能为空！");
  }
  else if(vicontent==''){
    Ext.MessageBox.alert('系统提示',"事迹内容不能为空！");
  }
  else if(vitype=='select'){
    Ext.MessageBox.alert('系统提示',"请选择评选类型！");
  }
  else if(file==''){
  	Ext.MessageBox.alert('系统提示',"请选择上传头像！");
  }
  else{
  $.post("/webvote/vote.do?action=updatevoter",{"viname":viname,"visex":visex,"viage":viage,"viintro":viintro,"vicontent":vicontent,
  "vitype":vitype,"viimg":viimg,"viid":viid,"org.apache.struts.taglib.html.TOKEN":token},function(text){
		if(text == "success"){
			Ext.MessageBox.alert('系统提示',"修改评选人信息成功！");
		}
		else if(text == "error")
		{
			Ext.MessageBox.alert('系统提示',"修改评选人信息失败！");
		}
		else if(text == "nopower")
		{
			Ext.MessageBox.alert('系统提示',"权限不足！");
		}
		else if(text == "repeat")
		{
			Ext.MessageBox.alert('系统提示',"请不要重复操作！");
		}
	});
	}
}else{
	Ext.MessageBox.alert('系统提示','您取消了本次任务！');
}
}

var viid="";
function deleteVoter(id){
  viid=id;
  Ext.MessageBox.confirm('系统提示','删除评选人信息？',verifydel);
}
function verifydel(btn){
 if(btn == 'yes'){
   $.post("/webvote/vote.do?action=deletevoter",{"viid":viid},function(text){
		    //window.alert("进入");
		   if(text == "success"){
				Ext.MessageBox.alert('系统提示',"用户删除成功！");
				location.reload();//刷新网页
			}else{
				Ext.MessageBox.alert('系统提示',"用户删除失败！");
			}
		});
}else{
	Ext.MessageBox.alert('系统提示','您取消了本次任务！');
}
}

//投票
function voteUI(id){
     $.post("/webvote/vote.do?action=voteop",{"viid":id},function(text){
		    //window.alert("进入");
		   if(text == "success"){
				//Ext.MessageBox.alert('系统提示',"投票成功！");
				location.reload();//刷新网页
			}else{
				alert("投票失败！");
			}
		});
}

